package GUI;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.swing.AbstractButton;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import GUI.manager.VentanaFactory;
import GUI.manager.VentanaManager;

import core.model.Categoria;
import core.model.Producto;
import core.model.Subcategoria;
import core.model.Sugerencia;

public class panelSugerencias extends javax.swing.JPanel implements
		ActionListener, ItemListener, MouseListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 190895204754661101L;
	private static final int OK_CANCEL_OPTION = 0;
	private static final int PLAIN_MESSAGE = 0;

	/**
	 * Creates new form principalSugerencias
	 */
	public panelSugerencias() {
		initComponents();
	}

	private void initComponents() {

		bTitulo = new javax.swing.JButton();
		bSugerencias = new javax.swing.JButton();
		bCrearLista = new javax.swing.JButton();
		bHistorial = new javax.swing.JButton();
		etiquetaNick = new javax.swing.JLabel();
		botonSalir = new javax.swing.JButton();
		panelCentro = new javax.swing.JPanel();
		eCategoriaProducto = new javax.swing.JLabel();
		eSubcategoriaProducto = new javax.swing.JLabel();
		eCantidadProducto = new javax.swing.JLabel();
		eSubcategoriaProducto1 = new javax.swing.JLabel();
		tfCantidad = new javax.swing.JTextField();
		tfNombre = new javax.swing.JTextField();
		cbSubcategoria = new javax.swing.JComboBox<String>();
		eNombreProducto = new javax.swing.JLabel();
		eCodigoProducto = new javax.swing.JLabel();
		cbCategoria = new javax.swing.JComboBox<String>();
		tfCodigoBarras = new javax.swing.JTextField();
		jScrollPane1 = new javax.swing.JScrollPane();
		tadescripcion = new javax.swing.JTextArea();
		bEnviar = new javax.swing.JButton();
		eUnidad = new javax.swing.JLabel();
		tfUnidad = new javax.swing.JTextField();
		bOpciones = new javax.swing.JButton();
		etiquetaEntrada = new javax.swing.JLabel();
		bBusqueda = new javax.swing.JButton();
		bAyuda = new javax.swing.JButton();
		eTipo = new javax.swing.JLabel();
		cTipo = new javax.swing.JComboBox<String>();

		setBackground(new java.awt.Color(255, 255, 255));

		bTitulo.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/encabezadoMain.png")); // NOI18N
		bTitulo.setBorder(null);
		bTitulo.setBorderPainted(false);
		bTitulo.addActionListener(this);
		bTitulo.setBackground(new java.awt.Color(255, 255, 255));

		bSugerencias.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bSugerencias.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonSugerencias.png")); // NOI18N
		bSugerencias.setBorderPainted(false);
		bSugerencias.addActionListener(this);
		bSugerencias.setBackground(new java.awt.Color(255, 255, 255));

		bCrearLista.setBackground(new java.awt.Color(255, 255, 255));
		bCrearLista.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bCrearLista.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonCrearLista.png")); // NOI18N
		bCrearLista.setBorderPainted(false);
		bCrearLista.addActionListener(this);

		bHistorial.setBackground(new java.awt.Color(255, 255, 255));
		bHistorial.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bHistorial.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonHistorial.png")); // NOI18N
		bHistorial.setBorderPainted(false);
		bHistorial.addActionListener(this);

		etiquetaNick.setBackground(new java.awt.Color(102, 102, 102));
		etiquetaNick.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		etiquetaNick.setText(panelPrincipal.nick);
		etiquetaNick.setToolTipText("");

		botonSalir.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/menu-salir.png")); // NOI18N
		botonSalir.setBorderPainted(false);
		botonSalir.addActionListener(this);
		botonSalir.setBackground(new java.awt.Color(255, 255, 255));

		panelCentro.setBackground(new java.awt.Color(255, 255, 255));

		eCategoriaProducto.setBackground(new java.awt.Color(255, 255, 255));
		eCategoriaProducto.setFont(new java.awt.Font("Lucida Handwriting", 1,
				13)); // NOI18N
		eCategoriaProducto.setForeground(new java.awt.Color(102, 102, 102));
		eCategoriaProducto.setText("CATEGORIA");

		eSubcategoriaProducto.setBackground(new java.awt.Color(255, 255, 255));
		eSubcategoriaProducto.setFont(new java.awt.Font("Lucida Handwriting",
				1, 13)); // NOI18N
		eSubcategoriaProducto.setForeground(new java.awt.Color(102, 102, 102));
		eSubcategoriaProducto.setText("SUBCATEGORIA");

		eCantidadProducto.setBackground(new java.awt.Color(102, 102, 102));
		eCantidadProducto
				.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eCantidadProducto.setForeground(new java.awt.Color(102, 102, 102));
		eCantidadProducto.setText("CANTIDAD");

		eSubcategoriaProducto1.setBackground(new java.awt.Color(102, 102, 102));
		eSubcategoriaProducto1.setFont(new java.awt.Font("Lucida Handwriting",
				1, 13)); // NOI18N
		eSubcategoriaProducto1.setForeground(new java.awt.Color(102, 102, 102));
		eSubcategoriaProducto1.setText("DESCRIPCION");

		tfCantidad.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tfCantidad.setToolTipText("");

		tfNombre.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tfNombre.setToolTipText("");

		eNombreProducto.setBackground(new java.awt.Color(255, 255, 255));
		eNombreProducto.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eNombreProducto.setForeground(new java.awt.Color(102, 102, 102));
		eNombreProducto.setText("NOMBRE");

		eCodigoProducto.setBackground(new java.awt.Color(255, 255, 255));
		eCodigoProducto.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eCodigoProducto.setForeground(new java.awt.Color(102, 102, 102));
		eCodigoProducto.setText("CODIGO DE BARRAS");

		// RELLENAR COMBOBOX
		List<String> listaNombresCategorias = new ArrayList<String>();
		List<Categoria> categorias = (List<Categoria>) obtenerCategorias();

		Iterator<Categoria> iterator = categorias.iterator();
		while (iterator.hasNext()) {
			Categoria categoria = iterator.next();
			listaNombresCategorias.add(String.valueOf(categoria.getNombre()));
		}
		String[] categoriasArrayString = new String[listaNombresCategorias
				.size()];
		listaNombresCategorias.toArray(categoriasArrayString);

		cbCategoria.setModel(new javax.swing.DefaultComboBoxModel<String>(
				categoriasArrayString));
		// FIN

		cbCategoria.addItemListener(this);

		cbSubcategoria.setEnabled(false);

		tfCodigoBarras.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tfCodigoBarras.setToolTipText("");

		tadescripcion.setColumns(20);
		tadescripcion.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tadescripcion.setRows(5);
		jScrollPane1.setViewportView(tadescripcion);
		tadescripcion.setEditable(false);

		bEnviar.setBackground(new java.awt.Color(255, 255, 255));
		bEnviar.setFont(new java.awt.Font("Lucida Handwriting", 1, 14)); // NOI18N
		bEnviar.setForeground(new java.awt.Color(243, 15, 120));
		bEnviar.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonEnviar.png")); // NOI18N
		bEnviar.setBorder(null);
		bEnviar.addActionListener(this);

		eUnidad.setBackground(new java.awt.Color(255, 255, 255));
		eUnidad.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eUnidad.setForeground(new java.awt.Color(102, 102, 102));
		eUnidad.setText("UNIDAD");

		tfUnidad.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tfUnidad.setToolTipText("");

		org.jdesktop.layout.GroupLayout panelCentroLayout = new org.jdesktop.layout.GroupLayout(
				panelCentro);
		panelCentro.setLayout(panelCentroLayout);
		panelCentroLayout
				.setHorizontalGroup(panelCentroLayout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(panelCentroLayout
								.createSequentialGroup()
								.addContainerGap()
								.add(panelCentroLayout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.LEADING)
										.add(eCantidadProducto)
										.add(eCategoriaProducto)
										.add(eSubcategoriaProducto)
										.add(eSubcategoriaProducto1))
								.add(58, 58, 58)
								.add(panelCentroLayout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.LEADING)
										.add(jScrollPane1,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												369,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(panelCentroLayout
												.createSequentialGroup()
												.add(panelCentroLayout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING,
																false)
														.add(cbCategoria,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																250,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
														.add(panelCentroLayout
																.createSequentialGroup()
																.add(tfCantidad,
																		org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																		150,
																		org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(
																		org.jdesktop.layout.LayoutStyle.RELATED,
																		org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)
																.add(eUnidad)))
												.addPreferredGap(
														org.jdesktop.layout.LayoutStyle.UNRELATED)
												.add(tfUnidad,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
														115,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.add(cbSubcategoria,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												250,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
								.addContainerGap(66, Short.MAX_VALUE))
						.add(org.jdesktop.layout.GroupLayout.TRAILING,
								panelCentroLayout
										.createSequentialGroup()
										.addContainerGap(
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE).add(bEnviar)
										.add(233, 233, 233)));
		panelCentroLayout
				.setVerticalGroup(panelCentroLayout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(panelCentroLayout
								.createSequentialGroup()
								.add(panelCentroLayout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.BASELINE)
										.add(tfCantidad,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(eCantidadProducto)
										.add(eUnidad)
										.add(tfUnidad,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
								.add(18, 18, 18)
								.add(panelCentroLayout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.BASELINE)
										.add(eCategoriaProducto)
										.add(cbCategoria,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
								.add(18, 18, 18)
								.add(panelCentroLayout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.BASELINE)
										.add(eSubcategoriaProducto)
										.add(cbSubcategoria,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
								.add(18, 18, 18)
								.add(panelCentroLayout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.LEADING)
										.add(eSubcategoriaProducto1)
										.add(jScrollPane1,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												49,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										org.jdesktop.layout.LayoutStyle.UNRELATED)
								.add(bEnviar,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										39,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
								.addContainerGap(22, Short.MAX_VALUE)));
		bOpciones.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bOpciones.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonOpciones.png")); // NOI18N
		bOpciones.setBorderPainted(false);
		bOpciones.addActionListener(this);
		bOpciones.setBackground(new java.awt.Color(255, 255, 255));

		etiquetaEntrada.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		etiquetaEntrada.setForeground(new java.awt.Color(243, 15, 120));
		etiquetaEntrada.setText("BIENVENIDO A LISTA DE LA COMPRA MAKER ");

		bBusqueda.setBackground(new java.awt.Color(255, 255, 255));
		bBusqueda.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bBusqueda.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonBusqueda.png")); // NOI18N
		bBusqueda.setToolTipText("");
		bBusqueda.setBorderPainted(false);
		bBusqueda.addActionListener(this);

		bAyuda.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bAyuda.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonAyuda.png")); // NOI18N
		bAyuda.setBorderPainted(false);
		bAyuda.addActionListener(this);
		bAyuda.setBackground(new java.awt.Color(255, 255, 255));

		eTipo.setBackground(new java.awt.Color(255, 255, 255));
		eTipo.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eTipo.setForeground(new java.awt.Color(102, 102, 102));
		eTipo.setText("TIPO DE SUGERENCIA");

		cTipo.setModel(new javax.swing.DefaultComboBoxModel<String>(
				new String[] { "Productos", "Otras" }));
		cTipo.addItemListener(this);

		org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
				this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(layout
						.createSequentialGroup()
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(layout
										.createSequentialGroup()
										.addContainerGap()
										.add(layout
												.createParallelGroup(
														org.jdesktop.layout.GroupLayout.LEADING)
												.add(layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.TRAILING)
														.add(bCrearLista,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																157,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
														.add(bBusqueda,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																155,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
														.add(bHistorial,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																157,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
														.add(bSugerencias,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																157,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
														.add(bOpciones,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																157,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
												.add(org.jdesktop.layout.GroupLayout.TRAILING,
														bAyuda,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
														157,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.add(layout
												.createParallelGroup(
														org.jdesktop.layout.GroupLayout.LEADING)
												.add(layout
														.createSequentialGroup()
														.add(46, 46, 46)
														.add(layout
																.createParallelGroup(
																		org.jdesktop.layout.GroupLayout.LEADING)
																.add(layout
																		.createSequentialGroup()
																		.add(eTipo)
																		.addPreferredGap(
																				org.jdesktop.layout.LayoutStyle.UNRELATED)
																		.add(cTipo,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																				314,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
																.add(layout
																		.createParallelGroup(
																				org.jdesktop.layout.GroupLayout.TRAILING,
																				false)
																		.add(layout
																				.createSequentialGroup()
																				.add(eCodigoProducto)
																				.addPreferredGap(
																						org.jdesktop.layout.LayoutStyle.RELATED,
																						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																						Short.MAX_VALUE)
																				.add(tfCodigoBarras,
																						org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																						350,
																						org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
																		.add(layout
																				.createSequentialGroup()
																				.add(eNombreProducto)
																				.add(109,
																						109,
																						109)
																				.add(tfNombre,
																						org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																						350,
																						org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
														.add(0, 0,
																Short.MAX_VALUE))
												.add(layout
														.createSequentialGroup()
														.add(35, 35, 35)
														.add(panelCentro,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE))))
								.add(layout.createSequentialGroup()
										.add(96, 96, 96).add(bTitulo)
										.add(44, 44, 44).add(botonSalir))
								.add(layout
										.createSequentialGroup()
										.add(84, 84, 84)
										.add(etiquetaEntrada)
										.add(46, 46, 46)
										.add(etiquetaNick,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												280,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
						.addContainerGap(
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE)));
		layout.setVerticalGroup(layout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(layout
						.createSequentialGroup()
						.add(6, 6, 6)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(bTitulo,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										104,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
								.add(botonSalir))
						.add(6, 6, 6)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(etiquetaEntrada).add(etiquetaNick))
						.add(18, 18, 18)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(layout
										.createSequentialGroup()
										.add(layout
												.createParallelGroup(
														org.jdesktop.layout.GroupLayout.BASELINE)
												.add(eTipo)
												.add(cTipo,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
														org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.add(44, 44, 44)
										.add(layout
												.createParallelGroup(
														org.jdesktop.layout.GroupLayout.BASELINE)
												.add(tfNombre,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
														org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
												.add(eNombreProducto))
										.add(18, 18, 18)
										.add(layout
												.createParallelGroup(
														org.jdesktop.layout.GroupLayout.BASELINE)
												.add(eCodigoProducto)
												.add(tfCodigoBarras,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
														org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.add(22, 22, 22)
										.add(panelCentro,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												245,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
								.add(layout
										.createSequentialGroup()
										.add(bBusqueda,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bCrearLista,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bHistorial,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bSugerencias,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bOpciones,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bAyuda,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
						.addContainerGap(
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE)));
	}

	private List<Categoria> obtenerCategorias() {
		VentanaManager ventanaManager = VentanaFactory.getInstance();
		List<Categoria> listaCategorias = ventanaManager.getAllCategorias();
		return listaCategorias;
	}

	private List<Subcategoria> obtenerSubcategorias(int cod_categoria) {
		VentanaManager ventanaManager = VentanaFactory.getInstance();
		List<Subcategoria> subcategorias = ventanaManager
				.getSubcategoriaByCodeCategoria(cod_categoria);
		return subcategorias;
	}

	// Variables declaration - do not modify
	private javax.swing.JButton bAyuda;
	private javax.swing.JButton bBusqueda;
	private javax.swing.JButton bCrearLista;
	private javax.swing.JButton bEnviar;
	private javax.swing.JButton bHistorial;
	private javax.swing.JButton bOpciones;
	private javax.swing.JButton bSugerencias;
	private javax.swing.JButton bTitulo;
	private javax.swing.JButton botonSalir;
	private javax.swing.JComboBox<String> cTipo;
	private javax.swing.JComboBox<String> cbCategoria;
	private javax.swing.JComboBox<String> cbSubcategoria;
	private javax.swing.JLabel eCantidadProducto;
	private javax.swing.JLabel eCategoriaProducto;
	private javax.swing.JLabel eCodigoProducto;
	private javax.swing.JLabel eNombreProducto;
	private javax.swing.JLabel eSubcategoriaProducto;
	private javax.swing.JLabel eSubcategoriaProducto1;
	private javax.swing.JLabel eTipo;
	private javax.swing.JLabel eUnidad;
	private javax.swing.JLabel etiquetaEntrada;
	private javax.swing.JLabel etiquetaNick;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JPanel panelCentro;
	private javax.swing.JTextArea tadescripcion;
	private javax.swing.JTextField tfCantidad;
	private javax.swing.JTextField tfCodigoBarras;
	private javax.swing.JTextField tfNombre;
	private javax.swing.JTextField tfUnidad;
	private JFrame actual;
	private JPanel estePanel = this;

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void itemStateChanged(ItemEvent e) {
		if (e.getSource() == cTipo) {

			if (cTipo.getSelectedItem().equals("Otras")) {
				actual = (JFrame) UtilidadesGUI
						.getContenedorPrincipal(estePanel);

				actual.getContentPane().remove(0);
				actual.getContentPane().add(new panelSugerenciasOtras());
				actual.setPreferredSize(new Dimension(850, 630));
				actual.pack();
				actual.repaint();
				UtilidadesGUI.CentrarPantalla(actual);
			}

		}

		if (e.getSource() == cbCategoria) {

			cbSubcategoria.setEnabled(true);

			String nombreCategoria = (String) cbCategoria.getSelectedItem();
			System.out.println(nombreCategoria);
			VentanaManager ventanaManager = VentanaFactory.getInstance();
			Categoria categoria = ventanaManager
					.getCategoriaByName(nombreCategoria);

			// RELLENAR COMBOBOX SUBCATEGORIA
			List<String> listaNombresSubcategorias = new ArrayList<String>();
			List<Subcategoria> subcategorias = obtenerSubcategorias(categoria
					.getCodigo_categoria());
			/*
			 * for (Iterator<Subcategoria> iterator = subcategorias.iterator();
			 * iterator.hasNext();) { Subcategoria subcategoria =
			 * iterator.next();
			 * listaNombresSubcategorias.add(String.valueOf(subcategoria
			 * .getNombre()));
			 * 
			 * System.out.println(subcategoria .getNombre()); }
			 */
			Iterator<Subcategoria> iterator = subcategorias.iterator();
			while (iterator.hasNext()) {
				Subcategoria subcategoria = iterator.next();
				listaNombresSubcategorias.add(String.valueOf(subcategoria
						.getNombre()));
			}
			String[] SubcategoriasArrayString = new String[listaNombresSubcategorias
					.size()];
			listaNombresSubcategorias.toArray(SubcategoriasArrayString);

			cbSubcategoria.setModel(new javax.swing.DefaultComboBoxModel(
					SubcategoriasArrayString));
			// FIN

		}

	}

	@Override
	public void actionPerformed(ActionEvent e) {

		if (e.getSource() == bBusqueda) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelBusqueda());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bHistorial) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelHistorial());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bOpciones) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelOpciones());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bAyuda) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelAyuda());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bCrearLista) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelCrearLista());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bTitulo) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelPrincipal());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == botonSalir) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelSalir(19));
			actual.setPreferredSize(new Dimension(610, 330));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bEnviar) {
			if((tfNombre.getText().length()==0)||(tfCodigoBarras.getText().length()==0)||(tfCantidad.getText().length()==0)
					||(tfUnidad.getText().length()==0)||(cbSubcategoria.getSelectedIndex()<0)){
				Icon icono = new ImageIcon("src/GUI/resources/error.gif");	
				
				JOptionPane.showOptionDialog(null, "Es necesario rellenar todos los campos",
				"Enviar sugerencia producto", OK_CANCEL_OPTION, PLAIN_MESSAGE, icono,
						new Object[] { "ACEPTAR" }, null);
			}else{
				
				Icon icono = new ImageIcon("src/GUI/resources/aceptar.gif");	
				
				JOptionPane.showOptionDialog(null, "Sugerencia enviada con exito",
				"Sugerencia Producto", OK_CANCEL_OPTION, PLAIN_MESSAGE, icono,
						new Object[] { "ACEPTAR" }, null);
			tadescripcion.setText("NOMBRE: "+tfNombre.getText() +"\n\n CODIGO DE BARRAS: "+tfCodigoBarras.getText()+ "\n\n CANTIDAD: " +tfCantidad.getText()
			+"\n\n UNIDAD: "+tfUnidad.getText()+"\n\n CATEGORIA: "+ cbCategoria.getSelectedItem().toString()+"\n\n SUBCATEGORIA: "+ cbSubcategoria.getSelectedItem().toString());
			
			
			AbstractButton taMensaje;
			Sugerencia sugerencia = new Sugerencia(cTipo.getSelectedIndex(), "Agregar Producto", tadescripcion.getText() , panelPrincipal.nick);
			VentanaManager ventanaManager = VentanaFactory.getInstance();
			ventanaManager.insertarSugerencia(sugerencia);
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelSugerencias());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}}

	}

	@Override
	public void mouseClicked(MouseEvent me) {
		
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

}